<?php
// htdocs/sms/index.php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set("display_errors", 0);
//date_default_timezone_set('Asia/Bangkok');
date_default_timezone_set('Asia/Ho_Chi_Minh');

//session
//86400: 1 day, 3600: 1 Hours, default 1440: 24 minutes
ini_set('session.gc_maxlifetime', 86400); 
session_set_cookie_params(86400);
session_name("MURAMASA");
session_start();
require_once(dirname(__FILE__)."/../dependency/config.php");
require_once(dirname(__FILE__)."/../dependency/set_inc_path.php");
require(PROJECT_PATH."/php/data/ViewColor.php");


//error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
//error_reporting(E_ALL);
//ini_set('display_errors', '1');

if(defined("DEBUG") && defined("ENABLE_XHPROF") && ENABLE_XHPROF) {
	// ??????????
	$prof = new XhprofManage;
}
// ??????????(??)
$response_start = microtime( true );
//?????
function ErrorViews()
{
	print("you cannot access.");
	Utility::terminate();
}

if (!isset($_REQUEST["MURAMASA"]))
{

	$_REQUEST["MURAMASA"]=session_id();

}
require_once(PROJECT_PATH."/php/class/ggee/GgeeSession.php");
$ggee_session = new GgeeSession();

// thaontt dong code 19-06-2013(bo social ggee)
if (!VIA_GAME_ROOT_DEBUG)
{
	$session_result = $ggee_session->execute();
	/*if ($session_result)
	{
		// signature????
		if ( !FAKE_PLATFORM_API && Utility::isOpenSocial() )
		{
			$api = new GgeeApi();
			if( $api->checkSignature() )
			{
				Log::debug(Log::OUTPUT_SYSTEM, "[signature:OK]");
			} else {
				Log::info(Log::OUTPUT_SYSTEM, "[signature:NG]");
				Log::debug( Log::OUTPUT_TOPREDIRECT, "[signature:NG]" );
				$url = GAME_ROOT . "index.php";
				Utility::redirect($url, null, null, true);
			}
		}
		else
		{
			if( !defined("DEBUG") )
			{
				Log::debug(Log::OUTPUT_SYSTEM, "sig error");
				Log::error(Log::OUTPUT_SYSTEM, "[OpenSocial:NG]");
				ErrorViews();
			}
		}
	}*/
}
// End thaontt dong code 19-06-2013(bo social ggee)

// ??????-----------------------------------------
require_once("Net/UserAgent/Mobile.php");
$userAgent = Net_UserAgent_Mobile::singleton();
switch(true) {
case	$userAgent->isDoCoMo():
	require_once("smarty/SmartyDocomo.php");
	$smarty = new SmartyDocomo();
	$session = new Session(Session::DEVICE_DOCOMO);
	if ( defined("DOCOMO_GUID_ON") ) {
		define("GUID_ON", "");
	}
	$session->set("pclogin", false);

	$guid = Utility::getGuid();
	if( is_null( $guid ) && !isset( $_REQUEST['guid'] ) ){
		Utility::topRedirect();
	}
	$smarty->assign("isFpDocomo", true);		// add hinohara 2012/03/28
	break;

case	$userAgent->isSoftBank():
	require_once("smarty/SmartySoftbank.php");
	$smarty = new SmartySoftbank();
	$session = new Session(Session::DEVICE_SOFTBANK);
	$session->set("pclogin", false);

	$smarty->assign("isFpSoftbank", true);		// add hinohara 2012/03/28
	break;

case	$userAgent->isEZweb():
	require_once("smarty/SmartyAu.php");
	$smarty = new SmartyAu();
	$session = new Session(Session::DEVICE_AU);
	$session->set("pclogin", false);

	$smarty->assign("isFpAu", true);		// add shirataka 2012/03/22
	break;

case	Login::isIPhone():
	// ???/iPhone????
	require_once("smarty/SmartySP.php");
	$smarty = new SmartySP(true);
	$session = new Session(Session::DEVICE_IPHONE);
	$session->set("pclogin", true);

	$smarty->assign("isIphone", true);		// add hinohara 2012/03/28
	break;

case	Login::isAndroid():
	// ???/android????
	require_once("smarty/SmartySP.php");
	$smarty = new SmartySP();
	$session = new Session(Session::DEVICE_ANDROID);
	$session->set("pclogin", true);

	//$smarty->assign("isAndroid", true);		// add hinohara 2012/03/28
	$smarty->assign("isIphone", true);	
	break;

default:
	// PC
	//Log::error(Log::OUTPUT_SYSTEM, "[DEVICE:PC]");
	//ErrorViews();
	require_once("smarty/SmartySP.php");
	$smarty = new SmartySP(true);
	$session = new Session(Session::DEVICE_IPHONE);
	$session->set("pclogin", true);

	$smarty->assign("isIphone", true);		// add hinohara 2012/03/28
	break;
}

//============Begin social quangnp

/*
	require_once(PROJECT_PATH."/php/class/moo/Moo.class.php");
	$moo = new Moo();
	$tmp = $moo->getPeople();
*/
	
	$logicName = "SmsLogic";
	$logicPath = PROJECT_PATH."/php/logic/i/view/{$logicName}.php";
	require_once($logicPath);
	$logic = new $logicName();
	$logic->execute($session, $request, $smarty);

	
Utility::terminate();
	